package com.cdwh.joylife;

import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;
import android.text.TextUtils;

import com.blankj.utilcode.util.Utils;
import com.cdwh.joylife.net.NetProvider;
import com.cdwh.joylife.net.RetrofitHelper;
import com.cdwh.joylife.net.Urls;
import com.cdwh.joylife.utils.ActivityManager;
import com.cdwh.joylife.utils.Constants;
import com.cdwh.joylife.utils.GlideIniter;
import com.cdwh.joylife.utils.SPUtils;
import com.umeng.analytics.MobclickAgent;

import java.util.HashMap;
import java.util.Map;

import me.iwf.photopicker.PhotoPickUtils;

/**
 * Created by huxing on 2018/2/8.
 */

public class App extends MultiDexApplication {

    private static Context context;
    private static ActivityManager activityManager;

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        Utils.init(this);
        activityManager = new ActivityManager();
        PhotoPickUtils.init(this, new GlideIniter());//第二个参数根据具体依赖库而定
        RetrofitHelper.init(new NetProvider() {
            @Override
            public String getBaseUrl() {
                return Urls.BASE_URL;
            }

            @Override
            public Map<String, String> getHeaders() {
                Map<String, String> map = new HashMap<>();
//                map.put("Cookie", "JSESSIONID=" + getToken() + ";" + getToken());
                String token = SPUtils.getToken();
                if (!TextUtils.isEmpty(token)) {
                    map.put("account-token", token);
                }
                map.put("Charset", "UTF-8");
                return map;
            }

            @Override
            public long getTimeout() {
                return Constants.APP.NET_TIMEOUT;
            }
        });

        MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);
    }

    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    public static Context getContext() {
        return context;
    }

    public static ActivityManager getActivityManager() {
        return activityManager;
    }
}
